//
//  OrdersViewController.m
//  YueYueSpecailCarDriver
//
//  Created by DL on 17/1/9.
//  Copyright © 2017年 黄旺鑫. All rights reserved.
//

#import "OrdersViewController.h"
#import "ongoingOrdersViewController.h"
#import <QXDriverConfiguration/QXDriverConfiguration.h>
#import "DLLApiManager.h"
#import <QXYueYueModels/QXYYOrderDetailModel.h>
#import <QXYueYueModels/QXYYUserPassengerModel.h>
#import <MJRefresh/MJRefresh.h>
#import "OrdersListTableViewCell.h"
#import "DLLApiManager.h"
#import "OrdersListModel.h"
#import "orderDetailsViewController.h"
#import "progressOrderDetailsViewController.h"
#import "paymentOrderDetailsViewController.h"
#import "endTheTripViewController.h"
#import "carEndTheTripViewController.h"
#import "UtilsMacros.h"
#import "orderDetailsViewController.h"
#import "progressOrderDetailsViewController.h"
#import "endTheTripViewController.h"
#import "paymentOrderDetailsViewController.h"
#import "HeaderMacro.h"
#import <DriverLoginManager/DriverLoginManager-umbrella.h>
#import "ConfigureKeyHeader.h"
#import <QXYueYueModels/QXYYUserDriverModel.h>
#import <QXDataManager/QXDataManager.h>
#import "IflyMSCManager.h"
#import "iflyMSC/iflyMSC.h"
#import "NotificationNameManager.h"

/// 等待接驾－预约订单
@interface OrdersViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;

/**
 订单列表数据源
 */
@property(nonatomic , strong) NSMutableArray *orderListDataSource;

/**
 当前订单列表页
 */
@property(nonatomic , assign) NSInteger nowPage;

@property(nonatomic , strong) NSIndexPath *selectIndexPath;


@end

@implementation OrdersViewController
- (NSMutableArray *)orderListDataSource {
    if (!_orderListDataSource) {
        _orderListDataSource = [[NSMutableArray alloc] init];
    }
    return _orderListDataSource;
}


+ (instancetype)ordersViewInstance {
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Root" bundle:nil];
    
    return [storyboard instantiateViewControllerWithIdentifier:@"OrdersViewController"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initializationData];
    
    __weak typeof(self) weakSelf = self;
    self.tableView.mj_header = [MJRefreshStateHeader headerWithRefreshingBlock:^{
        __strong typeof(self) strongSelf = weakSelf;
        strongSelf.nowPage = 1;
        QXYYUserDriverModel*drvier = [QXYYUserDriverModel QXYY_unarchiveObject];
        if(drvier.token){ // 如果没有登录,那么进入登录页面
            
            [strongSelf getOrderListWithNowPage:strongSelf.nowPage];
        }else {
            
            [strongSelf.tableView.mj_header endRefreshing];
        }

        
    }];
    
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        __strong typeof(self) strongSelf = weakSelf;
        strongSelf.nowPage += 1;
        QXYYUserDriverModel*drvier = [QXYYUserDriverModel QXYY_unarchiveObject];
        if(drvier.token){ // 如果没有登录,那么进入登录页面
            
            [strongSelf getOrderListWithNowPage:strongSelf.nowPage];
        }else {
            
            [strongSelf.tableView.mj_footer endRefreshing];
        }
    }];
    
    [self.tableView.mj_header beginRefreshing];
    
    [self registerPaySuccess]; // 支付成功action
    [self registerConfirmFare]; // 确认费用Action
    
    [self registerLoginStatus]; // 注册登录登出刷新的通知
    
    [self registerGrabOrderNotification];
    
    [self registerOrderChanged];
}

#pragma mark - 通知

#pragma mark - 注册支付成功的通知
- (void)registerPaySuccess {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paySuccessRefreshDetailVC:) name:NotificationName_PaySuccess object:nil];
}
- (void)paySuccessRefreshDetailVC:(NSNotification *)aNotification {
    
    if ([aNotification.name isEqualToString:NotificationName_PaySuccess]) {
        
        [self refreshSelectRowUI];
    }
}

#pragma mark - 订单改派
- (void)registerOrderChanged {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orderChanged:) name:LongLinkNoftificationName_OrderChanged object:nil];
}

- (void)orderChanged:(NSNotification *)aNotification {
    
    if ([aNotification.name isEqualToString:LongLinkNoftificationName_OrderChanged]) {
        
        [self.tableView.mj_header beginRefreshing];
    }
}


#pragma mark - 注册确认费用成功的通知
- (void)registerConfirmFare {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(confirmFareAction:) name:NotificationName_ConfirmFare object:nil];
}
- (void)confirmFareAction:(NSNotification *)aNotification {
    
    if ([aNotification.name isEqualToString:NotificationName_ConfirmFare]) {
        
        [self refreshSelectRowUI];
    }
}



#pragma mark - 注册登录登出的通知
- (void)registerLoginStatus {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginStatus:) name:DriverLoginSucessNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginStatus:) name:DriverLoginOutSucessNotification object:nil];
}

- (void)loginStatus:(NSNotification *)aNotification {
    
    if ([aNotification.name isEqualToString:DriverLoginSucessNotification]) {
        
//        [self refreshSelectRowUI];
//        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_header beginRefreshing];
    }
    if ([aNotification.name isEqualToString:DriverLoginOutSucessNotification]) {
        
        [self.orderListDataSource removeAllObjects];
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
        [MBProgressHUD hideHUDForView:self.view animated:NO];
    }
}

- (void)refreshSelectRowUI {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        if (self.orderListDataSource.count > self.selectIndexPath.section) {
            
            NSArray *arr = self.orderListDataSource[self.selectIndexPath.section];
            if (arr.count > self.selectIndexPath.row) {
                
                OrdersListModel *model = arr[self.selectIndexPath.row];
                
                QXYYUserDriverModel*drvier = [QXYYUserDriverModel QXYY_unarchiveObject]; // 如果登录才可以操作
                if(drvier.token){ // 如果没有登录,那么进入登录页面
                    [self getOrdersDetailsWithOrderId:model.uuid section:self.selectIndexPath.section row:self.selectIndexPath.row isJump:NO];
                }
            }
        }
        
    });
}


#pragma mark - 注册抢到订单通知
- (void)registerGrabOrderNotification {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(grabOrder:) name:NotificationName_GrabRealTimeOrder object:nil]; // 抢到即时订单
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(grabOrder:) name:NotificationName_GrabAppointTimeOrder object:nil]; // 抢到预约单
    
}

- (void)grabOrder:(NSNotification *)aNotification { // 抢到订单后刷新订单列表页面
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self.tableView.mj_header beginRefreshing];
    });
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 初始化UI
/**
 *  初始化数据
 */
- (void)initializationData {
    self.tableView.estimatedRowHeight = 100;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    // 加载图片和设置布局
    [self setupViews];

}

/**
 *  设置布局
 */
- (void)setupViews {
    
    self.backgroundImageView.image = [QXDriverConfiguration imageWithName:@"bg"];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.orderListDataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    NSArray *arr = self.orderListDataSource[section];
    return arr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ordersListCell" forIndexPath:indexPath];
    cell.backgroundColor=[UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    cell = [self dealOrdersListTableViewCellWithTableView:tableView indexPath:indexPath];
    
    return cell;
}

- (OrdersListTableViewCell *)dealOrdersListTableViewCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    
    NSArray *arr = self.orderListDataSource[indexPath.section];
    OrdersListModel *model = arr[indexPath.row];
    OrdersListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ordersListCell" forIndexPath:indexPath];
    
    [cell setValueWithOrdersListModel:model];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];
    headerView.backgroundColor = [UIColor clearColor];
    
    UILabel *headerViewTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, CGRectGetWidth(headerView.frame) - 30, 40)];
    headerViewTitleLabel.font = [UIFont systemFontOfSize:15];
    headerViewTitleLabel.textColor = [UIColor colorWithRed:189.0 / 255.0 green:200.0 / 255.0 blue:241.0 / 255.0 alpha:1.0];
    headerViewTitleLabel.backgroundColor = [UIColor clearColor];
    
    [headerView addSubview:headerViewTitleLabel];
    headerViewTitleLabel.frame = CGRectMake(15, 0, [UIScreen mainScreen].bounds.size.width - 30, 40);
    

    NSArray *arr = self.orderListDataSource[section];
    OrdersListModel *model = arr.firstObject;
    if (model.deparTime > 0) {
        
        headerViewTitleLabel.text = [self formatTimeStamp:model.deparTime withTimeFormatter:@"MM月dd日"];
    }else {
        
        headerViewTitleLabel.text = @"";
    }
    
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.01;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    self.selectIndexPath = indexPath;
    [self pushIntoOrderDetailWithIndexPath:indexPath];
}

// 进入订单详情
- (void)pushIntoOrderDetailWithIndexPath:(NSIndexPath *)indexPath {
    
    NSArray *arr = self.orderListDataSource[indexPath.section];
    OrdersListModel *model = arr[indexPath.row];
    [self getOrdersDetailsWithOrderId:model.uuid section:indexPath.section row:indexPath.row isJump:YES];
}

#pragma mark - 获取订单列表

/**
 获取订单列表
 */
- (void)getOrderListWithNowPage:(NSInteger)nowPage {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:@(nowPage) forKey:@"nowPage"];
    __weak typeof(self) weakSelf = self;
    
    [DLLApiManager getTheOrderListWithParameters:parameters success:^(id data) {
        
        __strong typeof(self) strongSelf = weakSelf;
        if (nowPage == 1) {
            
            [strongSelf.orderListDataSource removeAllObjects];
        }
        
        if (NetWork_Success) {
            
            NSArray *dataArray = [NSArray arrayWithArray:data[@"data"]];
            if ([dataArray isKindOfClass:[NSArray class]]) {
                
                if (dataArray.count > 0) {
                    
                    BOOL isCreateFirstArray = NO; // 是否创建了第一个数组
                    if (strongSelf.orderListDataSource.count > 0) {
                        
                        isCreateFirstArray = YES;
                    }
                    for (int i = 0; i < dataArray.count; i ++) {
                        
                        NSDictionary *dic = dataArray[i];
                        OrdersListModel *model = [OrdersListModel new];
                        [model setValuesForKeysWithDictionary:dic];
                        
                        if (!isCreateFirstArray) { // 如果没有创建第一个数组 既isCreateFirstArray = NO 的时候
                            
                            NSMutableArray *arrFirst = [[NSMutableArray alloc] init]; // 第一次创建

                            isCreateFirstArray = YES;
                            [arrFirst addObject:model];
                            [strongSelf.orderListDataSource addObject:arrFirst];
                            
                            continue;
                        }
                        
                        NSMutableArray *arrTemp = strongSelf.orderListDataSource.lastObject; // 获取数据源中的最后一个数组
                        OrdersListModel *modelTemp = arrTemp.lastObject;
                        if ([[strongSelf formatTimeStamp:modelTemp.deparTime withTimeFormatter:@"yyyyMMdd"] isEqualToString:[strongSelf formatTimeStamp:model.deparTime withTimeFormatter:@"yyyyMMdd"]]) {

                            [arrTemp addObject:model];

                        }else {
                            
                            NSMutableArray *arrNew = [NSMutableArray array];
                            [arrNew addObject:model];
                            [strongSelf.orderListDataSource addObject:arrNew];
                            
                        }
                    }
                
                    
                    
                }else {
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        MBProgressHUD *mb = [MBProgressHUD showWithText:NetWork_Message onView:strongSelf.view hiddenDuration:2.0];
                        mb.userInteractionEnabled = NO;
                    });
                }
            }
        }
        
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [strongSelf.tableView.mj_header endRefreshing];
            [strongSelf.tableView.mj_footer endRefreshing];
            [strongSelf.tableView reloadData];
        });
    } failure:^(NSError *error) {
        __strong typeof(self) strongSelf = weakSelf;
        dispatch_async(dispatch_get_main_queue(), ^{
            
            MBProgressHUD *hud = [MBProgressHUD showWithText:NetWorkNotToForce onView:strongSelf.view hiddenDuration:2.0];
            hud.userInteractionEnabled = NO;
            [strongSelf.tableView.mj_header endRefreshing];
            [strongSelf.tableView.mj_footer endRefreshing];
        });
    }];
    
}
#pragma mark -获取订单详情
- (void)getOrdersDetailsWithOrderId:(NSString *)orderId section:(NSInteger)section row:(NSInteger)row isJump:(BOOL)isJump {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        self.tableView.userInteractionEnabled = NO;
    });
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:orderId forKey:@"orderUuid"];
    __weak typeof(self) weakSelf = self;
    [DLLApiManager getTheOrderDetailsWithParameters:dic success:^(id data) {
        
        __strong typeof(self) strongSelf = weakSelf;
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [MBProgressHUD hideHUDForView:strongSelf.view animated:YES];
            strongSelf.tableView.userInteractionEnabled = YES;
        });

        
        if (NetWork_Success) {
            

            QXYYOrderDetailModel *ordersDetailsModel = [QXYYOrderDetailModel QXYY_objectWithKeyValues:data[@"data"]];
            QXYYUserPassengerModel *userPassengerModel = [QXYYUserPassengerModel QXYY_objectWithKeyValues:data[@"data"][@"passenger"]];
            
            if (strongSelf.orderListDataSource.count > section) {
                
                // 刷新UI
                NSArray *arr = strongSelf.orderListDataSource[section];
                if (arr.count > row) {
                    OrdersListModel *model = arr[row];
                    [model setValuesForKeysWithDictionary:data[@"data"]];
                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        [strongSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:(UITableViewRowAnimationNone)];
                    });

                }
            }
            if (isJump) { // 如果需要那么跳转,如果收到的是仅仅刷新某一行的UI获取的详情信息,这里不需要跳转
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [strongSelf dealOrderDetailWithStateNumber:ordersDetailsModel.subStatus OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel];
                });
                
            }
            
        }else {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                
                
                if ([[data allKeys] containsObject:@"data"]) {
                    
                    if ([data[@"data"] integerValue] == 20001) {
                        
                        IflyMSCManager *iflyMSCManager = [IflyMSCManager startSyntheticSpeechWithText:NetWork_Message];
                        [iflyMSCManager.iFlySpeechSynthesizer setParameter:[NSString stringWithFormat:@"80"]   forKey:[IFlySpeechConstant SPEED]];
                        NSMutableArray *arr = [strongSelf.orderListDataSource[section] mutableCopy];
                        [arr removeObjectAtIndex:row];
                        [strongSelf.tableView reloadData];
                    }
                }
                
                
                
                MBProgressHUD *mb = [MBProgressHUD showWithText:NetWork_Message onView:strongSelf.view hiddenDuration:1];
                mb.userInteractionEnabled = NO;
            });
        }
        
    } failure:^(NSError *error) {
        __strong typeof(self) strongSelf = weakSelf;
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:strongSelf.view animated:YES];
            strongSelf.tableView.userInteractionEnabled = YES;
            MBProgressHUD *mb = [MBProgressHUD showWithText:@"获取订单详情失败" onView:strongSelf.view hiddenDuration:1];
            mb.userInteractionEnabled = NO;
        });
    }];
}


#pragma mark - 订单跳转
/**
 根据订单状态处理不同的结果(进入不同的详情页面)
 */
- (void)dealOrderDetailWithStateNumber:(NSInteger)stateNumber OrdersDetailsModel:(QXYYOrderDetailModel *)ordersDetailsModel UserPassengerModel:(QXYYUserPassengerModel *)userPassengerModel {
    
    switch (stateNumber) {
            
        case OrderStatusCode_DriverReceivedOrder_DetermineStroke: // 200 行程未开始,预约订单
        {
            [self pushIntoOrdersDetailsViewControllerWithStateNumber:stateNumber OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel];
            break;
        }
            
        case OrderStatusCode_DriverSetOut_GoToPickUpPassengers: // 210［去接乘客］司机出发、去接乘客 . ［出租／专车］
        case OrderStatusCode_DriverArrived_WaitingForPassengers: // 220［等待乘客］司机到达、等待乘客 . ［出租／专车
        case OrderStatusCode_PickedUpPasengers_StrokeStart: // 进行中  300：［行程开始］乘客上车、行程开始 . ［出租／专车／拼车］
        {
            
            [self pushIntoongoingOrdersViewControllerWithStateNumber:stateNumber OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel];
            break;
        }
        
        case OrderStatusCode_PassengersArrivedDestination: // 400：［行程结束］司机送达目的地 ,这时候显示催款,提现页面
        {
            [self pushIntoendTheTripViewControllerWithStateNumber:stateNumber OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel];
            break;
            break;
        }
        
        
        case OrderStatusCode_DriverConfirmFare_WaitingForPassengersToPay: // 500：司机确认费用，等待乘客支付
        case OrderStatusCode_StrokeDetermination_PassengerCancelOrder_WaitingForPassengersToPayCancleFare: // 511：［行程确定］乘客取消，待支付取消费用
        case OrderStatusCode_StrokeDetermination_DriverCancelOrder_WaitingForPassengersToPayCancleFare: // 521：［行程确定］司机取消，待支付取消费用
        case OrderStatusCode_GotoPickUpPassengers_PassengerCancelOrder_WaitingForPassengersToPayCancleFare: // 512：［去接乘客］乘客取消，待支付取消费用
        case OrderStatusCode_GotoPickUpPassengers_DriverCancelOrder_WaitingForPassengersToPayCancleFare: // 522：［去接乘客］司机取消，待支付取消费用
        case OrderStatusCode_WaitingForPassengers_PassengerCancelOrder_WaitingForPassengersToPayCancleFare: // 513：［等待乘客］乘客取消，待支付取消费用
        case OrderStatusCode_WaitingForPassengers_DriverCancelOrder_WaitingForPassengersToPayCancleFare: // 523：［等待乘客］司机取消，待支付取消费用
        {
            
            [self pushIntopaymentOrderDetailsViewControllerWithStateNumber:stateNumber OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel];
            break;
        }
    
        
        case OrderStatusCode_PaymentCompleted_StrokeOver: // 600：付款完成、行程结束 , 不显示催款,提现页面
        case OrderStatusCode_PassengersHasCompletedEvaluationForDriver: // 610：乘客完成对车主评价 , 不显示催款,提现页面
        {
            
            [self pushIntopaymentOrderDetailsViewControllerWithStateNumber:stateNumber OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel];
            break;
        }
            
        // 这里处理无费用的取消订单
        case OrderStatusCode_NewStroke_PassengerCancel: // 900：［新行程］乘客取消
        case OrderStatusCode_PassengersCancel_StrokeDetemination_DriverNotArrive: // 901: 乘客取消（行程确定后、司机未到达
        case OrderStatusCode_PassengersCancel_StrokeDetemination_DriverArrived: // 902: 乘客取消（行程确定后、司机到达）
        case OrderStatusCode_NewStroke_DriverCancel: // 910：［新行程］司机取消
        case OrderStatusCode_NoFare_StrokeDetermination_PassengersCancelOrder: // 90200：［无费用］［行程确定］乘客取消订单
        case OrderStatusCode_NoFare_GotoPickUpPassengers_PassengersCancelOrder: // 90210：［无费用］［去接乘客］乘客取消订单
        case OrderStatusCode_NoFare_WaitingForPassengers_PassengersCancelOrder: // 90220：［无费用］［等待乘客］乘客取消订单
        case OrderStatusCode_NoFare_StrokeDetermination_DriverCancelOrder: // 91200：［无费用］［行程确定］司机取消订单
        case OrderStatusCode_NoFare_GotoPickUpPassengers_DriverCancelOrder: // 91210：［无费用］［去接乘客］司机取消订单
        case OrderStatusCode_NoFare_WaitingForPassengers_DriverCancelOrder: // 91220：［无费用］［等待乘客］司机取消订单
        case OrderStatusCode_OrderClosedByCustomerService: // 990：客服关闭订单
        {
            
            [self pushIntoOrdersDetailsViewControllerWithStateNumber:stateNumber OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel];
            break;
        }
        
        
        // 这里处理有费用的取消订单
        case OrderStatusCode_HaveFare_StrokeDetermination_PassengersCancelOrder: // 90511：［有费用］［行程确定］乘客取消订单
        case OrderStatusCode_HaveFare_GotoPickUpPassengers_PassengersCancelOrder: // 90512：［有费用］［去接乘客］乘客取消订单
        case OrderStatusCode_HaveFare_WaitingForPassengers_PassengersCancelOrder: // 90513：［有费用］［等待乘客］乘客取消订单
        case OrderStatusCode_HaveFare_StrokeDetermination_DriverCancelOrder: // 91521：［有费用］［行程确定］司机取消订单
        case OrderStatusCode_HaveFare_GotoPickUpPassengers_DriverCancelOrder: // 91522：［有费用］［去接乘客］司机取消订单
        case OrderStatusCode_HaveFare_WaitingForPassengers_DriverCancelOrder: // 91523：［有费用］［等待乘客］司机取消订单
        {
            [self pushIntopaymentOrderDetailsViewControllerWithStateNumber:stateNumber OrdersDetailsModel:ordersDetailsModel UserPassengerModel:userPassengerModel]; // 这里显示支付的费用
            break;
        }
            
        default:
            break;
    }
}


/**
 进入正在进行的订单页面 , 去接乘客,到达目的地,乘客已上车,前往目的地
 Code: 
    210：［去接乘客］司机出发、去接乘客
    220：［等待乘客］司机到达、等待乘客
    300：［行程开始］乘客上车、行程开始
 */
- (void)pushIntoongoingOrdersViewControllerWithStateNumber:(NSInteger)stateNumber OrdersDetailsModel:(QXYYOrderDetailModel *)ordersDetailsModel UserPassengerModel:(QXYYUserPassengerModel *)userPassengerModel {
    
    ongoingOrdersViewController *vc = [ongoingOrdersViewController shareSelf];
    vc.ordersDetailsModel = ordersDetailsModel;
    vc.userPassengerModel = userPassengerModel;
    
    dispatch_async(dispatch_get_main_queue(), ^{   // 抢到实时单后进入订单详情
//        [self.navigationController pushViewController:vc animated:YES];
    });
    
    [self.navigationController pushViewController:vc animated:YES];
}


/**
 进入订单详情,拨打客服电话,投诉
 Code:
    200：［行程确定］司机接单、行程确定 (预约单的状态,即时单没有这个状态)
    600：付款完成、行程结束
    610：乘客完成对车主评价
    900：［新行程］乘客取消
    901:  乘客取消（行程确定后、司机未到达）
    902:  乘客取消（行程确定后、司机到达）
    910: ［新行程］司机取消
    90200：［无费用］［行程确定］乘客取消订单
    90210：［无费用］［去接乘客］乘客取消订单
    90220：［无费用］［等待乘客］乘客取消订单
    91200：［无费用］［行程确定］司机取消订单
    91210：［无费用］［去接乘客］司机取消订单
    91220：［无费用］［等待乘客］司机取消订单
 
    90511：［有费用］［行程确定］乘客取消订单
    90512：［有费用］［去接乘客］乘客取消订单
    90513：［有费用］［等待乘客］乘客取消订单
    91521：［有费用］［行程确定］司机取消订单
    91522：［有费用］［去接乘客］司机取消订单
    91523：［有费用］［等待乘客］司机取消订单
    990：客服关闭订单
 */
- (void)pushIntoOrdersDetailsViewControllerWithStateNumber:(NSInteger)stateNumber OrdersDetailsModel:(QXYYOrderDetailModel *)ordersDetailsModel UserPassengerModel:(QXYYUserPassengerModel *)userPassengerModel {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        orderDetailsViewController *orderDetailVC = [orderDetailsViewController shareSelf];
        orderDetailVC.title = @"订单详情";
        orderDetailVC.ordersDetailsModel = ordersDetailsModel;
        orderDetailVC.userPassengerModel = userPassengerModel;
        [self.navigationController pushViewController:orderDetailVC animated:YES];
    });
    
}


/**
 进入结算页面,确认费用
 Code:
    400：［行程结束］司机送达目的地
 */
- (void)pushIntoendTheTripViewControllerWithStateNumber:(NSInteger)stateNumber OrdersDetailsModel:(QXYYOrderDetailModel *)ordersDetailsModel UserPassengerModel:(QXYYUserPassengerModel *)userPassengerModel {
    
    if ([ordersDetailsModel.typeTrip integerValue] == 1) {
        endTheTripViewController *endTheTripVC = [endTheTripViewController shareSelf];
        endTheTripVC.title = @"结算";
        endTheTripVC.userPassengerModel = userPassengerModel;
        endTheTripVC.ordersDetailsModel = ordersDetailsModel;
        [self.navigationController pushViewController:endTheTripVC animated:YES];
    }else if ([ordersDetailsModel.typeTrip integerValue] == 2 || [ordersDetailsModel.typeTrip integerValue] == 4 || [ordersDetailsModel.typeTrip integerValue] == 5 || [ordersDetailsModel.typeTrip integerValue] == 6 || [ordersDetailsModel.typeTrip integerValue] == 7) {
        
        carEndTheTripViewController *vc = [carEndTheTripViewController shareSelf];
        vc.ordersDetailsModel = ordersDetailsModel;
        vc.userPassengerModel = userPassengerModel;
        vc.title = @"结算";
        [self.navigationController pushViewController:vc animated:YES];
    }

}


/**
 进入催款详情页面页面
 Code:
    500：司机确认费用，等待乘客支付
    511：［行程确定］乘客取消，待支付取消费用
    521：［行程确定］司机取消，待支付取消费用
    512：［去接乘客］乘客取消，待支付取消费用
    522：［去接乘客］司机取消，待支付取消费用
    513：［等待乘客］乘客取消，待支付取消费用
    523：［等待乘客］司机取消，待支付取消费用
 */
- (void)pushIntopaymentOrderDetailsViewControllerWithStateNumber:(NSInteger)stateNumber OrdersDetailsModel:(QXYYOrderDetailModel *)ordersDetailsModel UserPassengerModel:(QXYYUserPassengerModel *)userPassengerModel {
    
    paymentOrderDetailsViewController *paymentOrderDetailVC = [paymentOrderDetailsViewController shareSelf];
    paymentOrderDetailVC.title = @"订单详情";
    paymentOrderDetailVC.userPassengerModel = userPassengerModel;
    paymentOrderDetailVC.ordersDetailsModel = ordersDetailsModel;
    [self.navigationController pushViewController:paymentOrderDetailVC animated:YES];
}

#pragma mark - 时间戳转化为指定格式的时间
- (NSString *)formatTimeStamp:(NSTimeInterval)timeStamp withTimeFormatter:(NSString *)timeFormatters
{
    //秒数
    NSTimeInterval interval = timeStamp / 1000.0;
    //date
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    //格式
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:timeFormatters];
    //时间
    NSString *timeStr = [format stringFromDate:date];
    
    return timeStr;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
